﻿using System.IO;
using System.Web;
using Api.Common;

namespace AppManager.Background
{
    public class CusBaseView<TModel> : BaseView<TModel>
    {
        public override void Execute()
        {
        }

        /// <summary>
        ///     獲取下載文件的地址
        /// </summary>
        /// <param name="downloadFile"></param>
        /// <param name="resourceId"></param>
        /// <param name="url">保存的路徑</param>
        /// <returns></returns>
        public IHtmlString GetDownloadFilePath(string downloadFile, int resourceId, string url)
        {
            if (!string.IsNullOrEmpty(url))
            {
                var serverPath = HttpContext.Current.Server.MapPath(url);
                if (File.Exists(serverPath))
                {
                    if (!downloadFile.EndsWith("/")) downloadFile += "/";
                    var path = downloadFile + resourceId;
                    return Html.Raw(string.Format("<a href={0}>文件下載</a>", path));
                }
            }

            return Html.Raw(string.Empty);
        }
    }
}